package com.ruoyi.quartz.util;

import java.util.Set;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

public class JedisUtil {
	private static JedisPool jedisPool;
	static {
		JedisPoolConfig config = new JedisPoolConfig();
		config.setMaxTotal(5);
		config.setMaxIdle(5);
		config.setMaxWaitMillis(3000);
		config.setTestOnBorrow(true);
		config.setTestOnReturn(true);
//		jedisPool = new JedisPool(config, "192.168.1.112", 6379, 0 ,"123456",0);
		jedisPool = new JedisPool(config, "redis", 6379, 0 ,"123456",0);
	}

	public static void main(String[] args) {
		JedisUtil.set("myname", "lxr");
		String vaule = JedisUtil.get("myname");
		System.out.println(vaule);
	}

	public static String set(String key, String value) {
		Jedis jedis = jedisPool.getResource();
		String result = jedis.set(key, value);
		jedis.close();
		return result;
	}

	public static String get(String key) {
		Jedis jedis = jedisPool.getResource();
		String result = jedis.get(key);
		jedis.close();
		return result;
	}

	public static Boolean exists(String key) {
		Jedis jedis = jedisPool.getResource();
		Boolean result = jedis.exists(key);
		jedis.close();
		return result;
	}

	public static Long expire(String key, int seconds) {
		Jedis jedis = jedisPool.getResource();
		Long result = jedis.expire(key, seconds);
		jedis.close();
		return result;
	}

	public static Long del(String key) {
		Jedis jedis = jedisPool.getResource();
		Long result = jedis.del(key);
		jedis.close();
		return result;
	}

	public static Set<String> keysByPre(String pre) {
		Jedis jedis = jedisPool.getResource();
		Set<String> result = jedis.keys(pre+"*");
		jedis.close();
		return result;
	}

}